(function ($, window) {
    var baseRequest = window.baseRequest;
    var appConfig = window.appConfig;
    var commonTool = window.commonTool;
    var dataManager = window.dataManager;
    var baseUrl = appConfig.baseServiceUrl;

    var v3Base = window.v3Base = {};

    //add by dongjuanying

    //end

    //add by zhangfuqiang

    var updateDevUrl = baseUrl + '/updateDevices';
    /**
     * 软件升级
     * @param devSN
     * @param fileSize
     * @param version 版本号
     * @param fileUrl
     * @param callback
     */
    v3Base.upgradeVersion = function (devSN, fileSize, version, fileUrl, callback) {
        baseRequest.commonPost(updateDevUrl, {
            param: [{
                devSN: devSN,
                fileSize: fileSize,
                devVersionUrl: fileUrl,
                softwareVersion: version
            }]
        }, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.retCode !== 0) {
                return callback(1, data.message);
            }
            callback(0, data.message);
        });
    };

    var upgradeStatus = appConfig.baseServiceUrl + '/getAllUpdateStatus';

    /**
     * 获取升级的进度
     * @param devSNs
     * @param callback
     * @example {"retCode":0,"message":[{"devVersionUrl":"https://oasisatauth.h3c.com/group2/M00/00/1F/rBUAFlkS0SCEUAVqAAAAAAAAAAA54..ipe","status":0,"percent":100,"eventMessage":"Downloading file completed.","devSN":"219801A0YF916CG02705","softwareVersion":"Version 7.1.064, Alpha 2320","lastUpdateTime":"2017-05-12T02:15:04.339Z","bIsUpdating":true,"versionWhenUp":"Version 7.1.064, Alpha 2320","versionNeedUp":"ESS 2424"},{"status":3,"percent":0,"eventMessage":"Not enough space.","devSN":"219801A18Y9173G00012","softwareVersion":"Version 7.1.064, ESS 2323","lastUpdateTime":"2017-05-11T01:24:48.038Z","bIsUpdating":false,"devVersionUrl":"https://oasisatauth.h3c.com/group1/M00/00/0A/rBUAFVjR1B-Eer5yAAAAAAAAAAA33..ipe","versionWhenUp":"Version 7.1.064, ESS 2323","versionNeedUp":"Alpha 2320"}]}
     */
    v3Base.getUpgradeStatus = function (devSNs, callback) {
        baseRequest.commonPost(upgradeStatus, {devSN: devSNs}, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data.retCode !== 0) {
                return callback(1, data.message);
            }
            callback(0, data.message);
        });
    };
    //end

    //add by ding
    //获取设备状态
    var getDevicesStatusUrl = baseUrl + "/getDevs";
    v3Base.getDevicesStatus = function(devSNs,callback){
    		//{"status":0,"detail":[{"devSN":"22658865565","status":1}]}
    		baseRequest.commonPost(getDevicesStatusUrl, {devSN: devSNs}, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if(data.status === 0){
            		callback(0,data.detail);
            }else{
            		callback(1);
            }
        });
    }
    
    //end

    //add by wangyu

    //end

    //add by wuchengcheng

    //end

})(mui, window);
